package com.example.educational.mapper;


import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.educational.entity.User;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.ArrayList;
import java.util.List;

/**
 * @author MySoul
 * @description 针对表【edu_user】的数据库操作Mapper
 * @createDate 2023-05-18 16:23:20
 * @Entity com.example.educational.entity/educationall.User
 */
@Mapper
public interface UserMapper extends BaseMapper<User> {


    @Insert("INSERT INTO edu_read_people(user_id, task_id) VALUES (#{user_id},#{task_id} ) ")
    int insertReadPeople(@Param("user_id") String userId, @Param("task_id") String taskId);

    ArrayList<String> selectIdsByNames(List<String> userNameList);


    @Select("SELECT edu_user.name, edu_read_people.create_time FROM edu_user RIGHT JOIN edu_read_people ON edu_user.id = edu_read_people.user_id\n" +
            "JOIN edu_notice_received ON edu_read_people.task_id = edu_notice_received.id " +
            "AND edu_read_people.task_id = #{task_id} " +
            "AND edu_user.name LIKE CONCAT('%',#{name},'%')")
    ArrayList<User> selectUsersReadByTaskId(@Param("task_id") String taskId, @Param("name") String name);

    @Select("SELECT edu_user.name FROM edu_user WHERE edu_user.id NOT IN (SELECT user_id FROM edu_read_people JOIN edu_notice_received ON edu_read_people.task_id = edu_notice_received.id " +
            "AND edu_read_people.task_id = #{task_id}) " +
            "AND edu_user.name LIKE CONCAT('%',#{name},'%')")
    ArrayList<User> selectUsersUnReadByTaskId(@Param("task_id") String taskId, @Param("name") String name);


}




